package io.zhifei.modules.sys.system.service.customer.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.zhifei.common.utils.PageUtils;
import io.zhifei.common.utils.ToolUtils;
import io.zhifei.modules.sys.system.dao.customer.CustomerFollowDao;
import io.zhifei.modules.sys.system.entity.customer.CustomerFollowEntity;
import io.zhifei.modules.sys.system.form.customer.CustomerFollowCalendarResult;
import io.zhifei.modules.sys.system.form.customer.CustomerFollowParam;
import io.zhifei.modules.sys.system.form.customer.CustomerFollowResult;
import io.zhifei.modules.sys.system.service.customer.CustomerFollowService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 客户跟进 服务实现类
 * </p>
 *
 * @author duke
 * @since 2020-12-10
 */
@Service
public class CustomerFollowServiceImpl extends ServiceImpl<CustomerFollowDao, CustomerFollowEntity> implements CustomerFollowService {

    @Override
    public void add(CustomerFollowParam param) {
        CustomerFollowEntity entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(CustomerFollowParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(CustomerFollowParam param) {
        CustomerFollowEntity oldEntity = getOldEntity(param);
        CustomerFollowEntity newEntity = getEntity(param);
        ToolUtils.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public CustomerFollowResult findBySpec(CustomerFollowParam param) {
        return null;
    }

    @Override
    public List<CustomerFollowResult> findListBySpec(CustomerFollowParam param) {
        return null;
    }

    @Override
    public PageUtils getPageList(Page page, CustomerFollowParam param) {
        IPage<CustomerFollowResult> pageList = this.baseMapper.getPageList(page,param);
        return new PageUtils(pageList);
    }

    @Override
    public List<CustomerFollowCalendarResult> getFollowCalendarList(CustomerFollowParam param) {
        return this.baseMapper.getFollowCalendarList(param);
    }


    private Serializable getKey(CustomerFollowParam param) {
        return param.getId();
    }


    private CustomerFollowEntity getOldEntity(CustomerFollowParam param) {
        return this.getById(getKey(param));
    }

    private CustomerFollowEntity getEntity(CustomerFollowParam param) {
        CustomerFollowEntity entity = new CustomerFollowEntity();
        ToolUtils.copyProperties(param, entity);
        return entity;
    }

}
